package com.fyp.ptma.dao.service;

import java.util.List;

import javax.persistence.PersistenceException;

import org.hibernate.HibernateException;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fyp.ptma.dao.exception.AuthenticationException;
import com.fyp.ptma.dao.repository.irepository.IUserDao;
import com.fyp.ptma.dao.service.iservice.IUserService;
import com.fyp.ptma.model.Application;
import com.fyp.ptma.model.User;

@Service
public class UserService implements IUserService {

	@Autowired
	private IUserDao userDao;

	@Transactional
	public Long save(Object objToSave) throws PersistenceException,
			ConstraintViolationException {

		return userDao.save(objToSave);
	}

	@Transactional
	public Long update(Object objToUpdate) throws PersistenceException {
		// TODO Auto-generated method stub
		return userDao.update(objToUpdate);
	}

	@Transactional
	public boolean delete(Object objToDelete) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub
		return userDao.delete(objToDelete);
	}

	@Transactional
	public List<Application> getAllApplications(User user)
			throws HibernateException {
		// TODO Auto-generated method stub
		return userDao.getAllApplications(user);
	}

	@Transactional
	public Application getApplication(User user) throws HibernateException {
		// TODO Auto-generated method stub
		return userDao.getApplication(user);
	}

	@Transactional
	public boolean authenticateLogin(User user) throws AuthenticationException,
			HibernateException {
		return userDao.authenticateLogin(user);
	}

	@Transactional
	public User getUserByEmail(String email) throws HibernateException {
		return userDao.getUserByEmail(email);
	}

	@Transactional
	public void saveOrUpdate(Object objToSave) throws PersistenceException,
			ConstraintViolationException {
		userDao.saveOrUpdate(objToSave);

	}

}
